﻿using SelfMadeMillionaire.Core;
using SelfMadeMillionaire.Core.Enums;
using SelfMadeMillionaire.Core.Services;
using SelfMadeMillionaire.Web.Infrastructure.Controllers;
using SelfMadeMillionaire.Web.Infrastructure.ViewModels.Admin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Security;

namespace SelfMadeMillionaire.Web.Infrastructure.Controllers.Admin
{	
	public class AccountController : AdminController
	{
		public ActionResult Index()
		{
			return RedirectToAction("Index", "Newsletters");
		}

		[AllowAnonymous]
		[HttpGet]
		public ActionResult Login()
		{
			return View();
		}

		[AllowAnonymous]
		[HttpPost]
		public ActionResult Login(LoginViewModel model)
		{
			if (FormsAuthentication.Authenticate(model.Login, model.Password))
			{
				Authenticate(model.Login, null, null, DateTime.Now.AddDays(1), ((int)UserRole.Admin).ToString(), false);

				return RedirectToAction("Index", "Newsletters");
			}

			return View(model);
		}

		[HttpGet]
		public ActionResult LogOut()
		{
			FormsAuthentication.SignOut();
            return Redirect(Url.Content("~/Account/Login"));
		}
	}
}
